package cn.com.thinvent.dispatch.service.biz.impl;

import cn.com.thinvent.dispatch.dao.DataCleaStoreConfigMapper;
import cn.com.thinvent.dispatch.dao.ModelDatasourceMapper;
import cn.com.thinvent.dispatch.entity.DataCleaStoreConfig;
import cn.com.thinvent.dispatch.entity.ModelDatasource;
import cn.com.thinvent.dispatch.entity.file.filevo;
import cn.com.thinvent.dispatch.entity.response.PagedGridResult;
import cn.com.thinvent.dispatch.service.biz.DataCleaStoreConfigService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
@Component
public class DataCleaStoreConfigServiceImpl implements DataCleaStoreConfigService {

    @Resource
    private DataCleaStoreConfigMapper dataCleaStoreConfigMapper;
    @Override
    public DataCleaStoreConfig saveOrUpdate(DataCleaStoreConfig dataCleaStoreConfig) {
        Date date = new Date();
        if(dataCleaStoreConfig.getId() == null) {
            dataCleaStoreConfig.setCreateTime(date);
            dataCleaStoreConfig.setUpdataTime(date);
            dataCleaStoreConfigMapper.insert(dataCleaStoreConfig);
        } else {
            dataCleaStoreConfig.setUpdataTime(date);
            dataCleaStoreConfigMapper.update(dataCleaStoreConfig);
        }
        return dataCleaStoreConfig;
    }


    @Override
    public PagedGridResult<DataCleaStoreConfig> list(Integer pageNum, Integer pageSize, String name) {
        PagedGridResult<DataCleaStoreConfig> pagedGridResult = new PagedGridResult<>();
        Integer pageBegin = (pageNum - 1) * pageSize;
        List<DataCleaStoreConfig> list = dataCleaStoreConfigMapper.list(pageBegin, pageSize, name);
        Long count = dataCleaStoreConfigMapper.count(pageBegin, pageSize);
        pagedGridResult.setRows(list);
        pagedGridResult.setRecords(count);
        pagedGridResult.setTotal((Integer.parseInt(count.toString()) + pageSize - 1 )/ pageSize);
        pagedGridResult.setPage(pageNum);
        return pagedGridResult;
    }
    @Override
    public Integer del(Integer id) {
        return dataCleaStoreConfigMapper.del(id);
    }
}
